/**
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package spring.cloud.tasks.api.service;

import spring.cloud.tasks.api.database.entity.DashboardHistoryDto;
import spring.cloud.tasks.api.database.entity.StatisticsDto;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface DashboardService {

    int executorInDockerCount(String key) throws RuntimeException;

    int executorNotInDockerCount(String key) throws RuntimeException;

    int jobCount(String key) throws RuntimeException;

    /**
     * 失败率top10的域列表
     */
    StatisticsDto top10FailureDomain(String key) throws RuntimeException;

    String top10FailureDomainByAllZkCluster() throws RuntimeException;

    /**
     * 根据失败率top10的作业列表
     */
    StatisticsDto top10FailureJob(String key) throws RuntimeException;

    String top10FailureJobByAllZkCluster() throws RuntimeException;

    /**
     * 最活跃作业的作业列表(即当天执行次数最多的作业)
     */
    StatisticsDto top10AactiveJob(String key) throws RuntimeException;

    String top10AactiveJobByAllZkCluster() throws RuntimeException;

    /**
     * 负荷最重的top10的Executor列表
     */
    StatisticsDto top10LoadExecutor(String key) throws RuntimeException;

    String top10LoadExecutorByAllZkCluster() throws RuntimeException;

    /**
     * 负荷最重的top10的作业列表以及其成功率
     */
    StatisticsDto top10LoadJob(String key) throws RuntimeException;

    String top10LoadJobByAllZkCluster() throws RuntimeException;

    /**
     * 稳定性最差的top10的域列表
     */
    StatisticsDto top10UnstableDomain(String key) throws RuntimeException;

    String top10UnstableDomainByAllZkCluster() throws RuntimeException;

    /**
     * 全域当天处理总数，失败总数
     */
    StatisticsDto allProcessAndErrorCountOfTheDay(String key) throws RuntimeException;

    String allProcessAndErrorCountOfTheDayByAllZkCluster() throws RuntimeException;

    StatisticsDto top10FailureExecutor(String key) throws RuntimeException;

    String top10FailureExecutorByAllZkCluster() throws RuntimeException;

    /**
     * 清除该域下的/$SaturnExecutors/sharding/count
     */
    void cleanShardingCount(String namespace) throws RuntimeException;

    void cleanOneJobAnalyse(String namespace, String jobName) throws RuntimeException;

    void cleanAllJobAnalyse(String namespace) throws RuntimeException;

    void cleanAllJobExecutorCount(String namespace) throws RuntimeException;

    void cleanOneJobExecutorCount(String namespace, String jobName) throws RuntimeException;

    Map<String, Integer> loadDomainRankDistribution(String key) throws RuntimeException;

    Map<String, Integer> loadDomainRankDistributionByAllZkCluster() throws RuntimeException;

    Map<Integer, Integer> loadJobRankDistribution(String key) throws RuntimeException;

    Map<Integer, Integer> loadJobRankDistributionByAllZkCluster() throws RuntimeException;

    Map<String, Long> versionDomainNumber(String key) throws RuntimeException;

    Map<String, Long> versionDomainNumberByAllZkCluster() throws RuntimeException;

    Map<String, Long> versionExecutorNumber(String key) throws RuntimeException;

    Map<String, Long> versionExecutorNumberByAllZkCluster() throws RuntimeException;

    /**
     * 保存dashboard历史
     *
     * @param zkCluster
     * @param type
     * @param topic
     * @param content
     */
    void saveDashboardHistory(String zkCluster, String type, String topic, String content);

    /**
     * 批量保存dashboard历史
     *
     * @param dashboardHistories
     */
    void batchSaveDashboardHistory(List<DashboardHistoryDto> dashboardHistories);

    /**
     * 获取domain历史
     */
    List<DashboardHistoryDto> getDashboardDomainHistory(String zkCluster, String type, String topic, Date fromDate,
                                                        Date toDate) throws RuntimeException;


    /**
     * 获取全域执行历史数据
     *
     * @param type
     * @param topic
     * @param fromDate
     * @param toDate
     * @return
     */
    Map<String, List> getDomainOperationHistory(String type, String topic, Date fromDate, Date toDate);

    /**
     * 获取某个集群域历史个数
     *
     * @param zkCluster
     * @param type
     * @param topic
     * @param fromDate
     * @param toDate
     * @return
     */
    Map<String, List> getDomainCountHistory(String zkCluster, String type, String topic, Date fromDate,
                                            Date toDate);

    /**
     * 获取Executor历史个数
     *
     * @param zkCluster
     * @param type
     * @param topic
     * @param fromDate
     * @param toDate
     * @return
     */
    Map<String, List> getExecutorHistory(String zkCluster, String type, String topic, Date fromDate,
                                         Date toDate);

    /**
     * 获取作业历史个数
     *
     * @param zkCluster
     * @param type
     * @param topic
     * @param fromDate
     * @param toDate
     * @return
     */
    Map<String, List> getJobCountHistory(String zkCluster, String type, String topic, Date fromDate,
                                         Date toDate);

}
